package jUnitTest;


import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import depot.Customer;
import depot.Customerlist;
import depot.IDFormatException;
import depot.Name;
import depot.NameValueException;

public class CustomerlistTest {

	private Customerlist customerList;
    private Customer customer1;
	private Customer customer2;
	private Customer customer3;
	
	/**
	 * set  up the record of customer
	 * @throws NameValueException
	 * @throws IDFormatException
	 */
	@Before
	public void setUp() throws NameValueException, IDFormatException{
		customerList = new Customerlist();
		customer1 = new Customer(1,new Name("John Brown"),"L020");
		customerList.addCustomer(customer1);
		customer2 = new Customer(2,new Name("John Black"),"N020");
		customerList.addCustomer(customer2);

		customer3 = new Customer(3,new Name("Amy Brown"),"N320");
		customerList.addCustomer(customer3);
	}
	
	@After
	public void tearDown(){
		
		customerList = new Customerlist();
	}
	
    /**
     * test the add customer function
     * @throws IDFormatException
     * @throws NameValueException
     */
	@Test
	public void testaddCustomer() throws IDFormatException, NameValueException{
		try{
			String message1 = "Faile for L120";
			assertTrue(message1, customerList.addCustomer(new Customer(4,new Name("John Brown"),"L120")));
		}
		catch(AssertionError ae){
			System.out.print(ae.getMessage());
		}
		
		
		try{
			String message2 = "Faile for L020";
			assertTrue(message2, customerList.addCustomer(new Customer(4,new Name("John Brown"),"L020")));
		}
		catch(AssertionError ae){
			System.out.print(ae.getMessage());
		}		
	}
	
	/**
	 * test the find customer function	
	 * @throws IDFormatException
	 * @throws NameValueException
	 */
	@Test
	public void testFindCustomer() throws IDFormatException, NameValueException{
		try{
			Customer expected = customer1;
			Customer actual= customerList.findCustomer(3);
			String message = "The customer has been found";
			assertSame(message, expected, actual);
		}
		
		catch(AssertionError ae){
			System.out.print(ae.getMessage());
		}

		try{
			Customer expected = new Customer(5,new Name("John Black"),"N050");
			Customer actual= customerList.findCustomer(0);
			String message = "The customer has been found";
			assertSame(message, expected, actual);
		}
		
		catch(AssertionError ae){
			System.out.print(ae.getMessage());
		}
	}
	
	/**
	 * test the remove customer function
	 */
	@Test
	public void testRemoveCustomer(){
		try{
			String message1 = "Remove for L233";
			assertTrue(message1, customerList.removeCustomer("L233"));
		}
		catch(AssertionError ae){
			System.out.print(ae.getMessage());
		}
		
		
		try{
			String message2 = "Faile for N020";
			assertTrue(message2, customerList.removeCustomer("N020"));
		}
		catch(AssertionError ae){
			System.out.print(ae.getMessage());
		}		
		
	}
}

